﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Bussiness.Manager;
public partial class Control_ProductMain : System.Web.UI.UserControl
{

    private int PRODID = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        Page1.ChangePage += new EventHandler(Page1_ChangePage);
        if (!IsPostBack)
            LoadRepParentData();
    }

    void Page1_ChangePage(object sender, EventArgs e)
    {
        LoadRepParentData();
    }

    public int INTID 
    {
        set {
            PRODID = value;
        }
        get {
            return PRODID;
        }
    }

    private void LoadRepParentData()
    {
        DataTable tabCategory = CmsCategoryManager.CreateInstant().GetCategoryListByLang("PROD", "vi-VN");
       
        if (tabCategory != null && tabCategory.Rows.Count > 0)
        {

            Page1.DataSource = tabCategory.DefaultView;
            Page1.BindToControl = repParent;
            repParent.DataSource = Page1.PagedDataSource;
            repParent.DataBind();
        }
        
    }

    public string GetTextID(string text) {
        return WB.Library.UnicodeConversion.CreateInstant().GetStringId(text);
    }

    protected void ItemBound(object sender, RepeaterItemEventArgs args)
    {
        RepeaterItem item = args.Item;
        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) {
            HiddenField hide = (HiddenField)item.FindControl("HiddenID");
            Repeater rep = (Repeater)item.FindControl("repChildren");
            DataTable tab = CmsProductsManager.CreateInstant().GetProductByCategoryTOP(Int32.Parse(hide.Value.Trim()), "vi-VN", "5",-1);
            if (tab != null && tab.Rows.Count > 0)
            {
                rep.DataSource = tab;
                rep.DataBind();
            }
        }
    }

}
